<?php 

include '../utils/stock.php';
include '../utils/evaluator.php';
require('../utils/fpdf17/fpdf.php');
session_start() ;
?>
<html>
<head>
<style type="text/css">
body
{

font-family:"Calibri";}
}
</style>
</head>
<body>

<b>Earnings (2 of 2)</b>
<br>

<br>

<?php
$years = $_POST["years"];
$eps2012 = $_POST["eps2012"];
$eps2011 = $_POST["eps2011"];
$eps2010 = $_POST["eps2010"];
$eps2009 = $_POST["eps2009"];
$eps2008 = $_POST["eps2008"];
$eps2007 = $_POST["eps2007"];
$eps2006 = $_POST["eps2006"];
$eps2005 = $_POST["eps2005"];
$eps2004 = $_POST["eps2004"];
$eps2003 = $_POST["eps2003"];
$growth2012 = ($eps2012 - $eps2011)/$eps2011;
$growth2011 = ($eps2011 - $eps2010)/$eps2010;
$growth2010 = ($eps2010 - $eps2009)/$eps2009;
$growth2009 = ($eps2009 - $eps2008)/$eps2008;
$growth2008 = ($eps2008 - $eps2007)/$eps2007;
$growth2007 = ($eps2007 - $eps2006)/$eps2006;
$growth2006 = ($eps2006 - $eps2005)/$eps2005;
$growth2005 = ($eps2005 - $eps2004)/$eps2004;
$growth2004 = ($eps2004 - $eps2003)/$eps2003;

$growth = array($growth2012,$growth2011, $growth2010, $growth2009, $growth2008, $growth2007,$growth2006,$growth2005,$growth2004);
$epsa = array($eps2012,$eps2011, $eps2010, $eps2009, $eps2008, $eps2007,$eps2006,$eps2005,$eps2004,$eps2003);

echo "<table border=1>";
echo "<tr>";
echo "<td><b>Year</b></td>";
echo "<td><b>Earnings per Share</b></td>";
echo "<td><b>EPS Growth</b></td>";
echo "</tr>";


echo "<tr>";
echo "<td>2012</td>";
echo "<td>".$eps2012."</td>";
echo "<td>".$growth2012."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2011</td>";
echo "<td>".$eps2011."</td>";
echo "<td>".$growth2011."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2010</td>";
echo "<td>".$eps2010."</td>";
echo "<td>".$growth2010."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2009</td>";
echo "<td>".$eps2009."</td>";
echo "<td>".$growth2009."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2008</td>";
echo "<td>".$eps2008."</td>";
echo "<td>".$growth2008."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2007</td>";
echo "<td>".$eps2007."</td>";
echo "<td>".$growth2007."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2006</td>";
echo "<td>".$eps2006."</td>";
echo "<td>".$growth2006."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2005</td>";
echo "<td>".$eps2005."</td>";
echo "<td>".$growth2005."</td>";
echo "</tr>";

echo "<tr>";
echo "<td>2004</td>";
echo "<td>".$eps2004."</td>";
echo "<td>".$growth2004."</td>";
echo "</tr>";


echo "</table>";


for ($i = 0; $i < $years - 1; $i++) {
    $sum += $growth[$i];
}
for ($i = 0; $i < $years ; $i++) {
    $epssum += $epsa[$i];
}
$averagegrowth = $sum / ($years -1);
$avg_eps = $epssum / $years;
echo "<br>";
echo "<b>Average growth ".$years." year(s): </b>";
echo $averagegrowth;
echo "<br>";



echo "<br>";
echo "<br>";
echo "Proceed if these numbers are correct, otherwise go back.";

$evaluator = $_SESSION['evaluator'];

$evaluator->avg_eps = $avg_eps;
$evaluator->avg_eps_growth = $averagegrowth;
$evaluator->nb_years_eps = $years;
$evaluator->eps2012 = $_POST["eps2012"];
$evaluator->eps2011 = $_POST["eps2011"];
$evaluator->eps2010 = $_POST["eps2010"];
$evaluator->eps2009 = $_POST["eps2009"];
$evaluator->eps2008 = $_POST["eps2008"];
$evaluator->eps2007 = $_POST["eps2007"];
$evaluator->eps2006 = $_POST["eps2006"];
$evaluator->eps2005 = $_POST["eps2005"];
$evaluator->eps2004 = $_POST["eps2004"];
$evaluator->eps2003 = $_POST["eps2003"];

$evaluator->epsg2012 = ($eps2012 - $eps2011)/$eps2011;
$evaluator->epsg2011 = ($eps2011 - $eps2010)/$eps2010;
$evaluator->epsg2010 = ($eps2010 - $eps2009)/$eps2009;
$evaluator->epsg2009 = ($eps2009 - $eps2008)/$eps2008;
$evaluator->epsg2008 = ($eps2008 - $eps2007)/$eps2007;
$evaluator->epsg2007 = ($eps2007 - $eps2006)/$eps2006;
$evaluator->epsg2006 = ($eps2006 - $eps2005)/$eps2005;
$evaluator->epsg2005 = ($eps2005 - $eps2004)/$eps2004;
$evaluator->epsg2004 = ($eps2004 - $eps2003)/$eps2003;


$_SESSION['evaluator'] = $evaluator;


function addColor($number, $reference){
	if($number >= $reference) 
	{
		$res = "<b><font color='green'>". $number . "</font></b>";
	}
	else 
	{
		$res = "<font color='red'>". $number . "</font>";
	}
	
	return $res;
}

?>


<br />
<button type="button" onclick="location.href='step3c.php'">Back</button>
<button type="button" onclick="location.href='step4.php'">Next</button>



</body>
</html> 